//
//  FilmCommentViewController.m
//  TravelFollowYourHeart
//
//  Created by ENERGY on 2018/1/22.
//  Copyright © 2018年 Lwx. All rights reserved.
//

#import "FilmCommentViewController.h"
#import "IWTextView.h"
@interface FilmCommentViewController ()<UITableViewDelegate>
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIButton * submitBtn;
@property (nonatomic, strong)IWTextView * textView;
@end

@implementation FilmCommentViewController(Networking)
- (void)submitCommentData{
    NSDictionary * dic = @{
                           @"mid":[UserModel intance].member_id,
                           @"token":[UserModel intance].token,
                           @"did":@(self.did),
                           @"type":@(2),
                           @"content":self.textView.text
                           };
    [[HttpRequest shardWebUtil] postNetworkRequestURLString:Url(@"/diary/toComment") andParas:dic andTransferGottenData:^(id obj, NSError *error) {
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
        if (error) {
            [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
        }else{
            if ([obj[@"code"] integerValue] == 100000){
//                if (ws.currentPage == 1) {
//                    
//                }
                [self.navigationController popViewControllerAnimated:YES];
            }else{
                [[HUDHelper sharedInstance] tipMessage:obj[@"msg"]];
            }
        }
    }];
}
@end

@implementation FilmCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"立即评价";
    self.view.backgroundColor = getColor(bgColor);
    [self.view addSubview:self.tableView];
    [self.tableView addSubview:self.submitBtn];
    [self.tableView addSubview:self.textView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
        _tableView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64);
        _tableView.backgroundColor = getColor(bgColor);
        _tableView.backgroundColor = getColor(bgColor);
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }return _tableView;
}

- (UIButton *)submitBtn{
    if (!_submitBtn) {
        int btnX = 15;
        int btnH = 40;
        int btnW = SCREEN_WIDTH - btnX*2;
        _submitBtn = [[UIButton alloc] init];
        _submitBtn.frame = CGRectMake(btnX, SCREEN_HEIGHT - btnH - 20 - 64, btnW, btnH);
        [_submitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_submitBtn setTitle:@"提交" forState:UIControlStateNormal];
        _submitBtn.backgroundColor = getColor(@"ffbb02");
        _submitBtn.layer.cornerRadius = 8;
        _submitBtn.titleLabel.font = DEF_FontSize_14;
        _submitBtn.layer.masksToBounds = YES;
        [_submitBtn addTarget:self action:@selector(submitButtonAction) forControlEvents:UIControlEventTouchUpInside];
    }return _submitBtn;
}

- (IWTextView *)textView{
    if (!_textView) {
        int border = 10;
        _textView = [[IWTextView alloc] init];
        _textView.frame = CGRectMake(border, border, SCREEN_WIDTH - 2*border, 200);
        _textView.backgroundColor = [UIColor whiteColor];
        _textView.placeholder = @"请输入……";
        
    }return _textView;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [self.textView resignFirstResponder];
}

- (void)submitButtonAction{
    NSLog(@"提交");
    if (self.textView.text.length == 0) {
        [[HUDHelper sharedInstance] tipMessage:@"请输入内容……"];
        return;
    }
    [self submitCommentData];
}

@end
